package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 复用性很差
     * @param setmeal
     * @return
     */
    @Select("select * from setmeal where category_id=#{setmeal.categoryId} and status=#{setmeal.status}")
    List<Setmeal> listTest(@Param("setmeal") Setmeal setmeal);

    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    @Select("select sd.name,sd.copies,d.image,d.description from setmeal_dish sd left join dish d on d.id=sd.dish_id  ")
    List<DishItemVO> getDishItemBySetmealId(Long id);

    Page<SetmealVO> pageQuery(SetmealPageQueryDTO pageDTO);
    @Update("update setmeal set status=#{status} where id=#{id}")
    @AutoFill(value = OperationType.UPDATE)
    void updateDishStatus(int status, Long id);

    void delete(Long[] ids);

    @AutoFill(value = OperationType.INSERT)
    void insert(Setmeal setmeal);

    @Select("select * from setmeal where id=#{id}")
    Setmeal getById(Long id);
    @Select("select * from setmeal_dish where id =#{id}")
    List<SetmealDish> getSetmealDishesBySetmealId(Long id);
}
